<?php
declare(strict_types=1);

use Yaf\Loader;
use Yaf\Plugin_Abstract;
use Yaf\Request_Abstract;
use Yaf\Response_Abstract;

class FormPlugin extends Plugin_Abstract
{
    public function postDispatch(Request_Abstract $request, Response_Abstract $response): void
    {
        if ($request->getParam("YafValidate")){
            $name = $request->getParam("YafValidate");
            if (class_exists($name)) {
                $validate = new $name();
                if (!$validate->check(Request::all())) {
                    apiError($validate->getError());
                }
            }
        }
    }

    public function preDispatch(Request_Abstract $request, Response_Abstract $response): void
    {

    }
}
